home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / include / linux / byteorder.h < prev    next >
Encoding:
C/C++ Source or Header  |  2009-09-09  |  5.6 KB  |  281 lines

  1. #ifndef _LINUX_BYTEORDER_H
  2. #define _LINUX_BYTEORDER_H
  3.  
  4. #include <linux/types.h>
  5. #include <linux/swab.h>
  6.  
  7. #if defined(__LITTLE_ENDIAN) && defined(__BIG_ENDIAN)
  8. # error Fix asm/byteorder.h to define one endianness
  9. #endif
  10.  
  11. #if !defined(__LITTLE_ENDIAN) && !defined(__BIG_ENDIAN)
  12. # error Fix asm/byteorder.h to define arch endianness
  13. #endif
  14.  
  15. #ifdef __LITTLE_ENDIAN
  16. # undef __LITTLE_ENDIAN
  17. # define __LITTLE_ENDIAN 1234
  18. #endif
  19.  
  20. #ifdef __BIG_ENDIAN
  21. # undef __BIG_ENDIAN
  22. # define __BIG_ENDIAN 4321
  23. #endif
  24.  
  25. #if defined(__LITTLE_ENDIAN) && !defined(__LITTLE_ENDIAN_BITFIELD)
  26. # define __LITTLE_ENDIAN_BITFIELD
  27. #endif
  28.  
  29. #if defined(__BIG_ENDIAN) && !defined(__BIG_ENDIAN_BITFIELD)
  30. # define __BIG_ENDIAN_BITFIELD
  31. #endif
  32.  
  33. #ifdef __LITTLE_ENDIAN
  34. # define __le16_to_cpu(x) ((__u16)(__le16)(x))
  35. # define __le32_to_cpu(x) ((__u32)(__le32)(x))
  36. # define __le64_to_cpu(x) ((__u64)(__le64)(x))
  37. # define __cpu_to_le16(x) ((__le16)(__u16)(x))
  38. # define __cpu_to_le32(x) ((__le32)(__u32)(x))
  39. # define __cpu_to_le64(x) ((__le64)(__u64)(x))
  40.  
  41. # define __be16_to_cpu(x) __swab16((__u16)(__be16)(x))
  42. # define __be32_to_cpu(x) __swab32((__u32)(__be32)(x))
  43. # define __be64_to_cpu(x) __swab64((__u64)(__be64)(x))
  44. # define __cpu_to_be16(x) ((__be16)__swab16(x))
  45. # define __cpu_to_be32(x) ((__be32)__swab32(x))
  46. # define __cpu_to_be64(x) ((__be64)__swab64(x))
  47. #endif
  48.  
  49. #ifdef __BIG_ENDIAN
  50. # define __be16_to_cpu(x) ((__u16)(__be16)(x))
  51. # define __be32_to_cpu(x) ((__u32)(__be32)(x))
  52. # define __be64_to_cpu(x) ((__u64)(__be64)(x))
  53. # define __cpu_to_be16(x) ((__be16)(__u16)(x))
  54. # define __cpu_to_be32(x) ((__be32)(__u32)(x))
  55. # define __cpu_to_be64(x) ((__be64)(__u64)(x))
  56.  
  57. # define __le16_to_cpu(x) __swab16((__u16)(__le16)(x))
  58. # define __le32_to_cpu(x) __swab32((__u32)(__le32)(x))
  59. # define __le64_to_cpu(x) __swab64((__u64)(__le64)(x))
  60. # define __cpu_to_le16(x) ((__le16)__swab16(x))
  61. # define __cpu_to_le32(x) ((__le32)__swab32(x))
  62. # define __cpu_to_le64(x) ((__le64)__swab64(x))
  63. #endif
  64.  
  65. /*
  66.  * These helpers could be phased out over time as the base version
  67.  * handles constant folding.
  68.  */
  69. #define __constant_htonl(x) __cpu_to_be32(x)
  70. #define __constant_ntohl(x) __be32_to_cpu(x)
  71. #define __constant_htons(x) __cpu_to_be16(x)
  72. #define __constant_ntohs(x) __be16_to_cpu(x)
  73.  
  74. #define __constant_le16_to_cpu(x) __le16_to_cpu(x)
  75. #define __constant_le32_to_cpu(x) __le32_to_cpu(x)
  76. #define __constant_le64_to_cpu(x) __le64_to_cpu(x)
  77. #define __constant_be16_to_cpu(x) __be16_to_cpu(x)
  78. #define __constant_be32_to_cpu(x) __be32_to_cpu(x)
  79. #define __constant_be64_to_cpu(x) __be64_to_cpu(x)
  80.  
  81. #define __constant_cpu_to_le16(x) __cpu_to_le16(x)
  82. #define __constant_cpu_to_le32(x) __cpu_to_le32(x)
  83. #define __constant_cpu_to_le64(x) __cpu_to_le64(x)
  84. #define __constant_cpu_to_be16(x) __cpu_to_be16(x)
  85. #define __constant_cpu_to_be32(x) __cpu_to_be32(x)
  86. #define __constant_cpu_to_be64(x) __cpu_to_be64(x)
  87.  
  88. static inline void __le16_to_cpus(__u16 *p)
  89. {
  90. #ifdef __BIG_ENDIAN
  91.     __swab16s(p);
  92. #endif
  93. }
  94.  
  95. static inline void __cpu_to_le16s(__u16 *p)
  96. {
  97. #ifdef __BIG_ENDIAN
  98.     __swab16s(p);
  99. #endif
  100. }
  101.  
  102. static inline void __le32_to_cpus(__u32 *p)
  103. {
  104. #ifdef __BIG_ENDIAN
  105.     __swab32s(p);
  106. #endif
  107. }
  108.  
  109. static inline void __cpu_to_le32s(__u32 *p)
  110. {
  111. #ifdef __BIG_ENDIAN
  112.     __swab32s(p);
  113. #endif
  114. }
  115.  
  116. static inline void __le64_to_cpus(__u64 *p)
  117. {
  118. #ifdef __BIG_ENDIAN
  119.     __swab64s(p);
  120. #endif
  121. }
  122.  
  123. static inline void __cpu_to_le64s(__u64 *p)
  124. {
  125. #ifdef __BIG_ENDIAN
  126.     __swab64s(p);
  127. #endif
  128. }
  129.  
  130. static inline void __be16_to_cpus(__u16 *p)
  131. {
  132. #ifdef __LITTLE_ENDIAN
  133.     __swab16s(p);
  134. #endif
  135. }
  136.  
  137. static inline void __cpu_to_be16s(__u16 *p)
  138. {
  139. #ifdef __LITTLE_ENDIAN
  140.     __swab16s(p);
  141. #endif
  142. }
  143.  
  144. static inline void __be32_to_cpus(__u32 *p)
  145. {
  146. #ifdef __LITTLE_ENDIAN
  147.     __swab32s(p);
  148. #endif
  149. }
  150.  
  151. static inline void __cpu_to_be32s(__u32 *p)
  152. {
  153. #ifdef __LITTLE_ENDIAN
  154.     __swab32s(p);
  155. #endif
  156. }
  157.  
  158. static inline void __be64_to_cpus(__u64 *p)
  159. {
  160. #ifdef __LITTLE_ENDIAN
  161.     __swab64s(p);
  162. #endif
  163. }
  164.  
  165. static inline void __cpu_to_be64s(__u64 *p)
  166. {
  167. #ifdef __LITTLE_ENDIAN
  168.     __swab64s(p);
  169. #endif
  170. }
  171.  
  172. static inline __u16 __le16_to_cpup(const __le16 *p)
  173. {
  174. #ifdef __LITTLE_ENDIAN
  175.     return (__u16)*p;
  176. #else
  177.     return __swab16p((__u16 *)p);
  178. #endif
  179. }
  180.  
  181. static inline __u32 __le32_to_cpup(const __le32 *p)
  182. {
  183. #ifdef __LITTLE_ENDIAN
  184.     return (__u32)*p;
  185. #else
  186.     return __swab32p((__u32 *)p);
  187. #endif
  188. }
  189.  
  190. static inline __u64 __le64_to_cpup(const __le64 *p)
  191. {
  192. #ifdef __LITTLE_ENDIAN
  193.     return (__u64)*p;
  194. #else
  195.     return __swab64p((__u64 *)p);
  196. #endif
  197. }
  198.  
  199. static inline __le16 __cpu_to_le16p(const __u16 *p)
  200. {
  201. #ifdef __LITTLE_ENDIAN
  202.     return (__le16)*p;
  203. #else
  204.     return (__le16)__swab16p(p);
  205. #endif
  206. }
  207.  
  208. static inline __le32 __cpu_to_le32p(const __u32 *p)
  209. {
  210. #ifdef __LITTLE_ENDIAN
  211.     return (__le32)*p;
  212. #else
  213.     return (__le32)__swab32p(p);
  214. #endif
  215. }
  216.  
  217. static inline __le64 __cpu_to_le64p(const __u64 *p)
  218. {
  219. #ifdef __LITTLE_ENDIAN
  220.     return (__le64)*p;
  221. #else
  222.     return (__le64)__swab64p(p);
  223. #endif
  224. }
  225.  
  226. static inline __u16 __be16_to_cpup(const __be16 *p)
  227. {
  228. #ifdef __BIG_ENDIAN
  229.     return (__u16)*p;
  230. #else
  231.     return __swab16p((__u16 *)p);
  232. #endif
  233. }
  234.  
  235. static inline __u32 __be32_to_cpup(const __be32 *p)
  236. {
  237. #ifdef __BIG_ENDIAN
  238.     return (__u32)*p;
  239. #else
  240.     return __swab32p((__u32 *)p);
  241. #endif
  242. }
  243.  
  244. static inline __u64 __be64_to_cpup(const __be64 *p)
  245. {
  246. #ifdef __BIG_ENDIAN
  247.     return (__u64)*p;
  248. #else
  249.     return __swab64p((__u64 *)p);
  250. #endif
  251. }
  252.  
  253. static inline __be16 __cpu_to_be16p(const __u16 *p)
  254. {
  255. #ifdef __BIG_ENDIAN
  256.     return (__be16)*p;
  257. #else
  258.     return (__be16)__swab16p(p);
  259. #endif
  260. }
  261.  
  262. static inline __be32 __cpu_to_be32p(const __u32 *p)
  263. {
  264. #ifdef __BIG_ENDIAN
  265.     return (__be32)*p;
  266. #else
  267.     return (__be32)__swab32p(p);
  268. #endif
  269. }
  270.  
  271. static inline __be64 __cpu_to_be64p(const __u64 *p)
  272. {
  273. #ifdef __BIG_ENDIAN
  274.     return (__be64)*p;
  275. #else
  276.     return (__be64)__swab64p(p);
  277. #endif
  278. }
  279.  
  280. #endif /* _LINUX_BYTEORDER_H */
  281.